<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>角色权限管理 - Kexio 管理系统</title>
  <!-- 引入Element Plus CSS -->
  <link rel="stylesheet" href="https://unpkg.com/element-plus@2.4.4/dist/index.css">
  <!-- 引入Font Awesome图标 -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <!-- 引入Tailwind CSS -->
  <script src="https://cdn.tailwindcss.com"></script>
  
  <!-- 配置Tailwind CSS自定义颜色和字体 -->
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            primary: '#000000',
            'primary-hover': '#333333',
            'primary-active': '#222222',
            'primary-weak': 'rgba(0, 0, 0, .05)',
            'text-primary': '#333333',
            'text-secondary': '#666666',
            'text-muted': '#999999',
            'bg-page': '#f5f5f5',
            'bg-panel': '#ffffff',
            'bg-hover': '#eeeeee',
            'border': '#dddddd',
            success: '#22c55e',
            warning: '#f59e0b',
            danger: '#ef4444',
            info: '#3b82f6'
          },
          fontFamily: {
            sans: ['Inter', 'system-ui', 'sans-serif']
          },
          boxShadow: {
            'card': '0 8px 16px rgba(15, 23, 42, .06)',
            'hover': '0 12px 24px rgba(15, 23, 42, .12)',
            'sm': '0 2px 6px rgba(15, 23, 42, .05)',
            'md': '0 6px 12px rgba(15, 23, 42, .08)',
            'lg': '0 10px 20px rgba(15, 23, 42, .10)'
          },
          borderRadius: {
            'sm': '8px',
            'md': '12px',
            'lg': '16px',
            'xl': '20px'
          }
        }
      }
    }
  </script>
  
  <!-- 自定义工具类 -->
  <style type="text/tailwindcss">
    @layer utilities {
      .content-auto {
        content-visibility: auto;
      }
      .menu-item-active {
        @apply bg-primary-weak text-primary border-r-4 border-primary;
      }
      .transition-sidebar {
        @apply transition-all duration-300 ease-in-out;
      }
      .scrollbar-hide::-webkit-scrollbar {
        display: none;
      }
      .scrollbar-hide {
        -ms-overflow-style: none;
        scrollbar-width: none;
      }
      .permission-checked {
        @apply bg-primary text-white;
      }
    }
  </style>
  
  <style>
    /* 全局样式重置 */
    body {
      margin: 0;
      padding: 0;
      font-family: 'Inter', system-ui, sans-serif;
      background-color: #f5f5f5;
      color: #333333;
    }
    
    /* 侧边栏样式 */
    .sidebar {
      height: 100vh;
      background-color: white;
      box-shadow: 0 2px 6px rgba(15, 23, 42, .05);
      z-index: 900;
    }
    
    .menu-item {
      transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .menu-item:hover {
      background-color: #f1f5f9;
    }
    
    /* 顶部导航样式 */
    .navbar {
      height: 60px;
      background-color: white;
      box-shadow: 0 2px 6px rgba(15, 23, 42, .05);
      z-index: 1000;
    }
    
    /* 面包屑样式 */
    .breadcrumb-item {
      color: #94a3b8;
    }
    
    .breadcrumb-item.active {
      color: #000000;
    }
    
    /* 卡片样式 */
    .card-hover {
      transition: all 0.3s ease;
    }
    
    .card-hover:hover {
      transform: translateY(-2px);
      box-shadow: 0 12px 24px rgba(15, 23, 42, .12);
    }
    
    /* 表格样式 */
    .table-row:hover {
      background-color: #f1f5f9;
    }
    
    /* 权限树样式 */
    .permission-tree {
      list-style: none;
      padding-left: 20px;
    }
    
    .permission-tree li {
      margin: 8px 0;
    }
    
    .permission-tree .permission-item {
      display: flex;
      align-items: center;
    }
    
    .permission-tree .permission-label {
      cursor: pointer;
      margin-left: 8px;
    }
    
    .permission-tree .permission-expand {
      cursor: pointer;
      margin-right: 8px;
      display: inline-block;
      width: 16px;
      text-align: center;
      font-size: 12px;
    }
    
    /* 加载动画 */
    @keyframes fadeIn {
      from { opacity: 0; transform: translateY(10px); }
      to { opacity: 1; transform: translateY(0); }
    }
    
    .animate-fadeIn {
      animation: fadeIn 0.3s ease-out;
    }
    
    /* 响应式设计 */
    @media (max-width: 768px) {
      .sidebar {
        transform: translateX(-100%);
        position: fixed;
      }
      
      .sidebar.open {
        transform: translateX(0);
      }
      
      .main-content {
        margin-left: 0 !important;
      }
    }
  </style>
</head>
<body class="bg-bg-page">
  <div class="flex h-screen overflow-hidden">
    <!-- 侧边栏 -->
    <aside id="sidebar" class="sidebar w-60 fixed left-0 top-0 bottom-0 transition-sidebar">
      <!-- Logo区域 -->
      <div class="flex items-center justify-center h-16 border-b border-border">
        <div class="text-primary font-bold text-xl flex items-center">
          <i class="fas fa-cube mr-2"></i>
          <span>Kexio</span>
        </div>
      </div>
      
      <!-- 菜单区域 -->
      <nav class="h-[calc(100vh-100px)] overflow-y-auto scrollbar-hide p-4">
        <div class="mb-4 text-xs text-text-muted uppercase font-semibold pl-2">主导航</div>
        
        <!-- 菜单项 -->
        <div class="space-y-1">
          <a href="index.html" class="flex items-center px-4 py-3 rounded-md text-text-secondary menu-item">
            <i class="fas fa-tachometer-alt w-5 text-center mr-3"></i>
            <span>仪表盘</span>
          </a>
          
          <a href="user-management.html" class="flex items-center px-4 py-3 rounded-md text-text-secondary menu-item">
            <i class="fas fa-users w-5 text-center mr-3"></i>
            <span>用户管理</span>
          </a>
          
          <a href="role-management.html" class="flex items-center px-4 py-3 rounded-md menu-item-active">
            <i class="fas fa-user-shield w-5 text-center mr-3"></i>
            <span>角色权限</span>
          </a>
          
          <a href="#" class="flex items-center px-4 py-3 rounded-md text-text-secondary menu-item">
            <i class="fas fa-sitemap w-5 text-center mr-3"></i>
            <span>组织架构</span>
          </a>
          
          <a href="#" class="flex items-center px-4 py-3 rounded-md text-text-secondary menu-item">
            <i class="fas fa-file-alt w-5 text-center mr-3"></i>
            <span>文件管理</span>
          </a>
          
          <a href="#" class="flex items-center px-4 py-3 rounded-md text-text-secondary menu-item">
            <i class="fas fa-cog w-5 text-center mr-3"></i>
            <span>系统设置</span>
          </a>
        </div>
        
        <div class="my-6 border-t border-border"></div>
        
        <div class="mb-4 text-xs text-text-muted uppercase font-semibold pl-2">扩展功能</div>
        
        <div class="space-y-1">
          <a href="#" class="flex items-center px-4 py-3 rounded-md text-text-secondary menu-item">
            <i class="fas fa-chart-line w-5 text-center mr-3"></i>
            <span>数据分析</span>
          </a>
          
          <a href="#" class="flex items-center px-4 py-3 rounded-md text-text-secondary menu-item">
            <i class="fas fa-bell w-5 text-center mr-3"></i>
            <span>消息中心</span>
            <span class="ml-auto bg-danger text-white text-xs px-2 py-0.5 rounded-full">3</span>
          </a>
        </div>
      </nav>
      
      <!-- 用户信息区域 -->
      <div class="absolute bottom-0 left-0 right-0 p-4 border-t border-border bg-white">
        <div class="flex items-center">
          <img src="https://picsum.photos/id/1005/40/40" alt="用户头像" class="w-10 h-10 rounded-full object-cover border-2 border-primary-weak">
          <div class="ml-3">
            <div class="text-text-primary font-medium">管理员</div>
            <div class="text-text-muted text-xs">超级管理员</div>
          </div>
          <button class="ml-auto text-text-muted hover:text-text-primary">
            <i class="fas fa-sign-out-alt"></i>
          </button>
        </div>
      </div>
    </aside>
    
    <!-- 主内容区域 -->
    <div id="main-content" class="flex-1 flex flex-col main-content ml-60 transition-sidebar">
      <!-- 顶部导航栏 -->
      <header class="navbar flex items-center justify-between px-6">
        <!-- 左侧按钮区域 -->
        <div class="flex items-center">
          <button id="sidebar-toggle" class="lg:hidden mr-4 text-text-secondary hover:text-primary">
            <i class="fas fa-bars text-xl"></i>
          </button>
          
          <!-- 面包屑导航 -->
          <nav class="hidden md:flex items-center space-x-2 text-sm">
            <a href="index.html" class="breadcrumb-item">首页</a>
            <i class="fas fa-chevron-right text-xs text-text-muted"></i>
            <span class="breadcrumb-item active">角色权限管理</span>
          </nav>
        </div>
        
        <!-- 右侧操作区域 -->
        <div class="flex items-center space-x-4">
          <!-- 搜索框 -->
          <div class="relative hidden md:block">
            <input type="text" placeholder="搜索..." class="pl-9 pr-4 py-2 rounded-md border border-border bg-bg-hover focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary w-60">
            <i class="fas fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-text-muted"></i>
          </div>
          
          <!-- 消息通知 -->
          <button class="relative p-2 text-text-secondary hover:text-primary hover:bg-bg-hover rounded-full">
            <i class="fas fa-bell text-lg"></i>
            <span class="absolute top-0 right-0 w-2 h-2 bg-danger rounded-full"></span>
          </button>
          
          <!-- 帮助中心 -->
          <button class="p-2 text-text-secondary hover:text-primary hover:bg-bg-hover rounded-full">
            <i class="fas fa-question-circle text-lg"></i>
          </button>
          
          <!-- 主题切换 -->
          <button class="p-2 text-text-secondary hover:text-primary hover:bg-bg-hover rounded-full">
            <i class="fas fa-moon text-lg"></i>
          </button>
        </div>
      </header>
      
      <!-- 内容区域 -->
      <main class="flex-1 overflow-y-auto p-6">
        <!-- 页面标题和操作按钮 -->
        <div class="flex flex-col md:flex-row md:items-center md:justify-between mb-6">
          <div>
            <h1 class="text-2xl font-bold text-text-primary">角色权限管理</h1>
            <p class="text-text-muted mt-2">创建和管理系统角色，并为角色分配相应的权限</p>
          </div>
          <div class="mt-4 md:mt-0">
            <button id="add-role-btn" class="bg-primary hover:bg-primary-hover text-white px-6 py-2 rounded-md flex items-center shadow-card transition-all">
              <i class="fas fa-plus mr-2"></i>
              <span>新增角色</span>
            </button>
          </div>
        </div>
        
        <!-- 角色列表和权限配置区域 -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
          <!-- 角色列表 -->
          <div class="lg:col-span-1">
            <div class="bg-white rounded-lg shadow-card overflow-hidden">
              <!-- 角色列表头部 -->
              <div class="p-4 border-b border-border bg-bg-hover">
                <div class="text-text-secondary font-medium">角色列表</div>
              </div>
              
              <!-- 角色列表内容 -->
              <div class="max-h-[calc(100vh-280px)] overflow-y-auto">
                <div id="role-list" class="divide-y divide-border">
                  <!-- 超级管理员角色 -->
                  <div class="p-4 cursor-pointer bg-primary-weak border-l-4 border-primary">
                    <div class="flex items-center justify-between">
                      <div class="font-medium text-text-primary">超级管理员</div>
                      <span class="text-xs text-text-muted">1人</span>
                    </div>
                    <div class="text-text-muted text-sm mt-1">系统最高权限，可管理所有功能</div>
                  </div>
                  
                  <!-- 管理员角色 -->
                  <div class="p-4 cursor-pointer hover:bg-bg-hover">
                    <div class="flex items-center justify-between">
                      <div class="font-medium text-text-primary">管理员</div>
                      <span class="text-xs text-text-muted">3人</span>
                    </div>
                    <div class="text-text-muted text-sm mt-1">管理普通用户和基础功能</div>
                  </div>
                  
                  <!-- 部门主管角色 -->
                  <div class="p-4 cursor-pointer hover:bg-bg-hover">
                    <div class="flex items-center justify-between">
                      <div class="font-medium text-text-primary">部门主管</div>
                      <span class="text-xs text-text-muted">5人</span>
                    </div>
                    <div class="text-text-muted text-sm mt-1">管理部门内部用户和数据</div>
                  </div>
                  
                  <!-- 普通员工角色 -->
                  <div class="p-4 cursor-pointer hover:bg-bg-hover">
                    <div class="flex items-center justify-between">
                      <div class="font-medium text-text-primary">普通员工</div>
                      <span class="text-xs text-text-muted">12人</span>
                    </div>
                    <div class="text-text-muted text-sm mt-1">基础的业务操作权限</div>
                  </div>
                  
                  <!-- 访客角色 -->
                  <div class="p-4 cursor-pointer hover:bg-bg-hover">
                    <div class="flex items-center justify-between">
                      <div class="font-medium text-text-primary">访客</div>
                      <span class="text-xs text-text-muted">8人</span>
                    </div>
                    <div class="text-text-muted text-sm mt-1">仅查看权限，无修改能力</div>
                  </div>
                </div>
              </div>
            </div>
            
            <!-- 角色说明卡片 -->
            <div class="bg-white rounded-lg shadow-card p-6 mt-6">
              <h3 class="text-lg font-semibold text-text-primary mb-4">角色管理说明</h3>
              <ul class="space-y-3 text-text-secondary text-sm">
                <li class="flex items-start">
                  <i class="fas fa-info-circle text-info mt-0.5 mr-2"></i>
                  <span>超级管理员拥有系统的全部权限，无法被删除或修改权限</span>
                </li>
                <li class="flex items-start">
                  <i class="fas fa-info-circle text-info mt-0.5 mr-2"></i>
                  <span>新建角色默认没有任何权限，需要手动分配权限</span>
                </li>
                <li class="flex items-start">
                  <i class="fas fa-info-circle text-info mt-0.5 mr-2"></i>
                  <span>修改角色权限后，相关用户的权限会立即生效</span>
                </li>
                <li class="flex items-start">
                  <i class="fas fa-info-circle text-info mt-0.5 mr-2"></i>
                  <span>删除角色前，请确保该角色下没有用户</span>
                </li>
              </ul>
            </div>
          </div>
          
          <!-- 权限配置 -->
          <div class="lg:col-span-2">
            <div class="bg-white rounded-lg shadow-card overflow-hidden">
              <!-- 权限配置头部 -->
              <div class="p-4 border-b border-border bg-bg-hover">
                <div class="text-text-secondary font-medium">权限配置</div>
                <div class="text-text-muted text-sm mt-1">为「超级管理员」角色分配系统权限</div>
              </div>
              
              <!-- 权限配置操作区 -->
              <div class="p-4 border-b border-border flex justify-between items-center">
                <div class="text-sm text-text-secondary">
                  <span class="font-medium text-primary">32</span> 项权限已配置
                </div>
                <div class="flex space-x-2">
                  <button id="select-all-btn" class="px-4 py-1.5 border border-border rounded-md text-text-secondary hover:bg-bg-hover text-sm">全选</button>
                  <button id="deselect-all-btn" class="px-4 py-1.5 border border-border rounded-md text-text-secondary hover:bg-bg-hover text-sm">取消全选</button>
                  <button id="expand-all-btn" class="px-4 py-1.5 border border-border rounded-md text-text-secondary hover:bg-bg-hover text-sm">展开全部</button>
                  <button id="collapse-all-btn" class="px-4 py-1.5 border border-border rounded-md text-text-secondary hover:bg-bg-hover text-sm">收起全部</button>
                </div>
              </div>
              
              <!-- 权限树 -->
              <div class="p-6 max-h-[calc(100vh-280px)] overflow-y-auto">
                <!-- 系统管理模块 -->
                <div class="mb-6">
                  <div class="flex items-center mb-3">
                    <div class="permission-expand" data-target="system-module">
                      <i class="fas fa-chevron-down text-text-muted"></i>
                    </div>
                    <div class="permission-item">
                      <input type="checkbox" id="system-module-checkbox" class="permission-checkbox" checked>
                      <label for="system-module-checkbox" class="permission-label font-medium">系统管理</label>
                    </div>
                  </div>
                  <ul class="permission-tree" id="system-module">
                    <!-- 管理员账户 -->
                    <li>
                      <div class="flex items-center mb-3">
                        <div class="permission-expand" data-target="admin-account">
                          <i class="fas fa-chevron-down text-text-muted"></i>
                        </div>
                        <div class="permission-item">
                          <input type="checkbox" id="admin-account-checkbox" class="permission-checkbox" checked>
                          <label for="admin-account-checkbox" class="permission-label">管理员账户</label>
                        </div>
                      </div>
                      <ul class="permission-tree" id="admin-account">
                        <li class="permission-item">
                          <input type="checkbox" id="view-admin-account" class="permission-checkbox" checked>
                          <label for="view-admin-account" class="permission-label">查看管理员账户</label>
                        </li>
                        <li class="permission-item">
                          <input type="checkbox" id="edit-admin-account" class="permission-checkbox" checked>
                          <label for="edit-admin-account" class="permission-label">编辑管理员账户</label>
                        </li>
                        <li class="permission-item">
                          <input type="checkbox" id="delete-admin-account" class="permission-checkbox" checked>
                          <label for="delete-admin-account" class="permission-label">删除管理员账户</label>
                        </li>
                        <li class="permission-item">
                          <input type="checkbox" id="add-admin-account" class="permission-checkbox" checked>
                          <label for="add-admin-account" class="permission-label">添加管理员账户</label>
                        </li>
                      </ul>
                    </li>
                    
                    <!-- 系统设置 -->
                    <li>
                      <div class="flex items-center mb-3">
                        <div class="permission-expand" data-target="system-settings">
                          <i class="fas fa-chevron-down text-text-muted"></i>
                        </div>
                        <div class="permission-item">
                          <input type="checkbox" id="system-settings-checkbox" class="permission-checkbox" checked>
                          <label for="system-settings-checkbox" class="permission-label">系统设置</label>
                        </div>
                      </div>
                      <ul class="permission-tree" id="system-settings">
                        <li class="permission-item">
                          <input type="checkbox" id="view-system-settings" class="permission-checkbox" checked>
                          <label for="view-system-settings" class="permission-label">查看系统设置</label>
                        </li>
                        <li class="permission-item">
                          <input type="checkbox" id="edit-system-settings" class="permission-checkbox" checked>
                          <label for="edit-system-settings" class="permission-label">修改系统设置</label>
                        </li>
                        <li class="permission-item">
                          <input type="checkbox" id="reset-system-settings" class="permission-checkbox" checked>
                          <label for="reset-system-settings" class="permission-label">重置系统设置</label>
                        </li>
                      </ul>
                    </li>
                  </ul>
                </div>
                
                <!-- 用户管理模块 -->
                <div class="mb-6">
                  <div class="flex items-center mb-3">
                    <div class="permission-expand" data-target="user-module">
                      <i class="fas fa-chevron-down text-text-muted"></i>
                    </div>
                    <div class="permission-item">
                      <input type="checkbox" id="user-module-checkbox" class="permission-checkbox" checked>
                      <label for="user-module-checkbox" class="permission-label font-medium">用户管理</label>
                    </div>
                  </div>
                  <ul class="permission-tree" id="user-module">
                    <!-- 用户列表 -->
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="view-user-list" class="permission-checkbox" checked>
                        <label for="view-user-list" class="permission-label">查看用户列表</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="add-user" class="permission-checkbox" checked>
                        <label for="add-user" class="permission-label">添加用户</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="edit-user" class="permission-checkbox" checked>
                        <label for="edit-user" class="permission-label">编辑用户</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="delete-user" class="permission-checkbox" checked>
                        <label for="delete-user" class="permission-label">删除用户</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="import-user" class="permission-checkbox" checked>
                        <label for="import-user" class="permission-label">导入用户</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="export-user" class="permission-checkbox" checked>
                        <label for="export-user" class="permission-label">导出用户</label>
                      </div>
                    </li>
                  </ul>
                </div>
                
                <!-- 角色管理模块 -->
                <div class="mb-6">
                  <div class="flex items-center mb-3">
                    <div class="permission-expand" data-target="role-module">
                      <i class="fas fa-chevron-down text-text-muted"></i>
                    </div>
                    <div class="permission-item">
                      <input type="checkbox" id="role-module-checkbox" class="permission-checkbox" checked>
                      <label for="role-module-checkbox" class="permission-label font-medium">角色管理</label>
                    </div>
                  </div>
                  <ul class="permission-tree" id="role-module">
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="view-role-list" class="permission-checkbox" checked>
                        <label for="view-role-list" class="permission-label">查看角色列表</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="add-role" class="permission-checkbox" checked>
                        <label for="add-role" class="permission-label">添加角色</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="edit-role" class="permission-checkbox" checked>
                        <label for="edit-role" class="permission-label">编辑角色</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="delete-role" class="permission-checkbox" checked>
                        <label for="delete-role" class="permission-label">删除角色</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="assign-permission" class="permission-checkbox" checked>
                        <label for="assign-permission" class="permission-label">分配权限</label>
                      </div>
                    </li>
                  </ul>
                </div>
                
                <!-- 组织管理模块 -->
                <div class="mb-6">
                  <div class="flex items-center mb-3">
                    <div class="permission-expand" data-target="org-module">
                      <i class="fas fa-chevron-down text-text-muted"></i>
                    </div>
                    <div class="permission-item">
                      <input type="checkbox" id="org-module-checkbox" class="permission-checkbox" checked>
                      <label for="org-module-checkbox" class="permission-label font-medium">组织管理</label>
                    </div>
                  </div>
                  <ul class="permission-tree" id="org-module">
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="view-org-structure" class="permission-checkbox" checked>
                        <label for="view-org-structure" class="permission-label">查看组织架构</label>
                      </div>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="edit-org-structure" class="permission-checkbox" checked>
                        <label for="edit-org-structure" class="permission-label">编辑组织架构</label>
                      </div>
                    </li>
                  </ul>
                </div>
                
                <!-- 数据管理模块 -->
                <div class="mb-6">
                  <div class="flex items-center mb-3">
                    <div class="permission-expand" data-target="data-module">
                      <i class="fas fa-chevron-down text-text-muted"></i>
                    </div>
                    <div class="permission-item">
                      <input type="checkbox" id="data-module-checkbox" class="permission-checkbox" checked>
                      <label for="data-module-checkbox" class="permission-label font-medium">数据管理</label>
                    </div>
                  </div>
                  <ul class="permission-tree" id="data-module">
                    <li>
                      <div class="flex items-center mb-3">
                        <div class="permission-expand" data-target="data-backup">
                          <i class="fas fa-chevron-down text-text-muted"></i>
                        </div>
                        <div class="permission-item">
                          <input type="checkbox" id="data-backup-checkbox" class="permission-checkbox" checked>
                          <label for="data-backup-checkbox" class="permission-label">数据备份</label>
                        </div>
                      </div>
                      <ul class="permission-tree" id="data-backup">
                        <li class="permission-item">
                          <input type="checkbox" id="create-backup" class="permission-checkbox" checked>
                          <label for="create-backup" class="permission-label">创建备份</label>
                        </li>
                        <li class="permission-item">
                          <input type="checkbox" id="restore-backup" class="permission-checkbox" checked>
                          <label for="restore-backup" class="permission-label">恢复备份</label>
                        </li>
                        <li class="permission-item">
                          <input type="checkbox" id="delete-backup" class="permission-checkbox" checked>
                          <label for="delete-backup" class="permission-label">删除备份</label>
                        </li>
                      </ul>
                    </li>
                    <li>
                      <div class="permission-item">
                        <input type="checkbox" id="data-statistics" class="permission-checkbox" checked>
                        <label for="data-statistics" class="permission-label">数据统计</label>
                      </div>
                    </li>
                  </ul>
                </div>
              </div>
              
              <!-- 权限配置底部 -->
              <div class="p-4 border-t border-border flex justify-end space-x-4">
                <button class="px-6 py-2 border border-border rounded-md text-text-secondary hover:bg-bg-hover">取消</button>
                <button id="save-permissions-btn" class="px-6 py-2 bg-primary text-white rounded-md hover:bg-primary-hover shadow-sm">保存配置</button>
              </div>
            </div>
          </div>
        </div>
      </main>
    </div>
  </div>
  
  <!-- 新增角色弹窗 -->
  <div id="add-role-modal" class="fixed inset-0 bg-black/50 flex items-center justify-center z-50 hidden">
    <div class="bg-white rounded-lg shadow-lg w-full max-w-lg max-h-[90vh] overflow-hidden flex flex-col animate-fadeIn">
      <!-- 弹窗头部 -->
      <div class="p-6 border-b border-border flex justify-between items-center">
        <h3 class="text-lg font-semibold text-text-primary">新增角色</h3>
        <button id="close-role-modal-btn" class="text-text-muted hover:text-text-primary">
          <i class="fas fa-times"></i>
        </button>
      </div>
      
      <!-- 弹窗内容 -->
      <div class="p-6 overflow-y-auto flex-1">
        <form id="add-role-form">
          <!-- 角色名称 -->
          <div class="mb-6">
            <label class="block text-text-secondary mb-2 text-sm font-medium">角色名称 <span class="text-danger">*</span></label>
            <input type="text" class="w-full px-4 py-2 rounded-md border border-border focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary" placeholder="请输入角色名称">
          </div>
          
          <!-- 角色描述 -->
          <div class="mb-6">
            <label class="block text-text-secondary mb-2 text-sm font-medium">角色描述</label>
            <textarea class="w-full px-4 py-2 rounded-md border border-border focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary" rows="3" placeholder="请输入角色描述信息"></textarea>
          </div>
          
          <!-- 权限模板 -->
          <div class="mb-6">
            <label class="block text-text-secondary mb-2 text-sm font-medium">权限模板</label>
            <select class="w-full px-4 py-2 rounded-md border border-border focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary">
              <option value="">不使用模板</option>
              <option value="admin">管理员模板</option>
              <option value="department">部门主管模板</option>
              <option value="employee">普通员工模板</option>
              <option value="guest">访客模板</option>
            </select>
            <div class="text-text-muted text-xs mt-2">选择模板后，系统将自动为新角色分配对应权限</div>
          </div>
        </form>
      </div>
      
      <!-- 弹窗底部 -->
      <div class="p-6 border-t border-border flex justify-end space-x-4">
        <button id="cancel-role-btn" class="px-6 py-2 border border-border rounded-md text-text-secondary hover:bg-bg-hover">取消</button>
        <button id="submit-role-btn" class="px-6 py-2 bg-primary text-white rounded-md hover:bg-primary-hover shadow-sm">确定</button>
      </div>
    </div>
  </div>
  
  <!-- 页面交互脚本 -->
  <script>
    // 侧边栏切换
    document.getElementById('sidebar-toggle').addEventListener('click', function() {
      const sidebar = document.getElementById('sidebar');
      sidebar.classList.toggle('open');
    });
    
    // 权限树展开/收起功能
    document.querySelectorAll('.permission-expand').forEach(expand => {
      expand.addEventListener('click', function() {
        const targetId = this.getAttribute('data-target');
        const targetElement = document.getElementById(targetId);
        const icon = this.querySelector('i');
        
        if (targetElement.style.display === 'none') {
          targetElement.style.display = 'block';
          icon.classList.remove('fa-chevron-right');
          icon.classList.add('fa-chevron-down');
        } else {
          targetElement.style.display = 'none';
          icon.classList.remove('fa-chevron-down');
          icon.classList.add('fa-chevron-right');
        }
      });
    });
    
    // 权限全选/取消全选
    document.getElementById('select-all-btn').addEventListener('click', function() {
      document.querySelectorAll('.permission-checkbox').forEach(checkbox => {
        checkbox.checked = true;
      });
    });
    
    document.getElementById('deselect-all-btn').addEventListener('click', function() {
      document.querySelectorAll('.permission-checkbox').forEach(checkbox => {
        checkbox.checked = false;
      });
    });
    
    // 展开/收起全部
    document.getElementById('expand-all-btn').addEventListener('click', function() {
      document.querySelectorAll('.permission-tree').forEach(tree => {
        tree.style.display = 'block';
      });
      document.querySelectorAll('.permission-expand i').forEach(icon => {
        icon.classList.remove('fa-chevron-right');
        icon.classList.add('fa-chevron-down');
      });
    });
    
    document.getElementById('collapse-all-btn').addEventListener('click', function() {
      document.querySelectorAll('.permission-tree').forEach(tree => {
        tree.style.display = 'none';
      });
      document.querySelectorAll('.permission-expand i').forEach(icon => {
        icon.classList.remove('fa-chevron-down');
        icon.classList.add('fa-chevron-right');
      });
    });
    
    // 权限复选框联动（父级选择影响子级）
    document.querySelectorAll('.permission-checkbox').forEach(checkbox => {
      checkbox.addEventListener('change', function() {
        const parentId = this.id.replace('-checkbox', '');
        const childCheckboxes = document.querySelectorAll(`#${parentId} .permission-checkbox`);
        
        // 父级影响子级
        if (childCheckboxes.length > 0) {
          childCheckboxes.forEach(child => {
            child.checked = this.checked;
          });
        }
        
        // 子级影响父级（简单实现）
        updateParentCheckbox(this);
      });
    });
    
    function updateParentCheckbox(checkbox) {
      // 查找最近的父级模块
      const parentModule = checkbox.closest('.permission-tree').parentNode;
      if (!parentModule) return;
      
      const parentCheckbox = parentModule.querySelector('.permission-checkbox');
      if (!parentCheckbox) return;
      
      const childCheckboxes = parentModule.querySelectorAll('.permission-tree .permission-checkbox');
      if (childCheckboxes.length === 0) return;
      
      let allChecked = true;
      let anyChecked = false;
      
      childCheckboxes.forEach(child => {
        if (!child.checked) {
          allChecked = false;
        } else {
          anyChecked = true;
        }
      });
      
      // 如果所有子级都选中，父级也选中
      parentCheckbox.checked = allChecked;
    }
    
    // 角色切换
    document.querySelectorAll('#role-list > div').forEach(role => {
      role.addEventListener('click', function() {
        document.querySelectorAll('#role-list > div').forEach(r => {
          r.classList.remove('bg-primary-weak', 'border-l-4', 'border-primary');
          r.classList.add('hover:bg-bg-hover');
        });
        
        this.classList.add('bg-primary-weak', 'border-l-4', 'border-primary');
        this.classList.remove('hover:bg-bg-hover');
        
        // 更新权限配置区域的角色名称
        const roleName = this.querySelector('.font-medium').textContent;
        document.querySelector('.text-sm.mt-1').textContent = `为「${roleName}」角色分配系统权限`;
      });
    });
    
    // 新增角色弹窗
    const addRoleModal = document.getElementById('add-role-modal');
    
    // 打开弹窗
    document.getElementById('add-role-btn').addEventListener('click', function() {
      addRoleModal.classList.remove('hidden');
      // 防止背景滚动
      document.body.style.overflow = 'hidden';
    });
    
    // 关闭弹窗
    function closeRoleModal() {
      addRoleModal.classList.add('hidden');
      // 恢复背景滚动
      document.body.style.overflow = '';
    }
    
    document.getElementById('close-role-modal-btn').addEventListener('click', closeRoleModal);
    document.getElementById('cancel-role-btn').addEventListener('click', closeRoleModal);
    
    // 点击弹窗外部关闭
    addRoleModal.addEventListener('click', function(e) {
      if (e.target === addRoleModal) {
        closeRoleModal();
      }
    });
    
    // 提交表单
    document.getElementById('submit-role-btn').addEventListener('click', function() {
      // 这里可以添加表单验证和提交逻辑
      alert('角色创建成功！');
      closeRoleModal();
    });
    
    // 保存权限配置
    document.getElementById('save-permissions-btn').addEventListener('click', function() {
      // 这里可以添加保存权限配置的逻辑
      alert('权限配置保存成功！');
    });
  </script>
</body>
</html>